<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
			<u-form-item :label-position="labelPosition" label="问题描述" label-width="150" required>
				<u-input type="textarea" :border="border" placeholder="请填写问题描述" v-model="wentms" />
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="上传图片" label-width="150">
				<u-upload multiple max-count="9" :action="action" :header="header" @on-success="onSuccess" @on-remove="onRemove"></u-upload>
			</u-form-item>
		</u-form>
		<u-button @click="submit">报修</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList: [9],
				wentms: "",
				header: {
					"X-Access-Token": uni.getStorageSync("token")
				},
				action: getApp().globalData.serviceUrl + "/sys/common/upload",
				rules: {},
				border: false,
				labelPosition: 'left',
				codeTips: '',
				errorType: ['message'],
			};
		},
		onLoad() {

		},
		computed: {

		},
		onReady() {

		},
		methods: {
			// 删除图片
			onRemove(index, lists) {
				this.fileList.splice(index, 1)
			},
						
			onSuccess(data, index, lists, name) {
				if (data.success)
					this.fileList[index] = data.message
			},
			
			submit() {
				if (!this.wentms) {
					uni.showToast({
						title: '问题描述必填!',
						icon: 'none'
					});
					return
				}
				
				uni.request({
					url: getApp().globalData.serviceUrl + "/baox/kuybBaox/add",
					data: {
						wentms: this.wentms,
						tup: this.fileList.join(",")
					},
					header: {
						"X-Access-Token": uni.getStorageSync("token")
					},
					method: 'POST',
					success: (resp) => {
						if (resp.data.success) {
							uni.showToast({
								title: resp.data.message,
								icon: 'none'
							});
						} 
					}
				})
			},

		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}
</style>
